#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->comboBox->addItem("麦辣鸡腿堡");
    ui->comboBox->addItem("巨无霸");
    ui->comboBox->addItem("培根蔬萃双层牛堡");

    ui->comboBox_2->addItem("中薯条");
    ui->comboBox_2->addItem("麦辣鸡块");
    ui->comboBox_2->addItem("麦辣鸡翅");

    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");

    //设置微调框的范围
    ui->spinBox->setRange(1,5);
    ui->spinBox_2->setRange(1,5);
    ui->spinBox_3->setRange(1,5);

    ui->spinBox->setValue(1);
    ui->spinBox_2->setValue(1);
    ui->spinBox_3->setValue(1);

    ui->spinBox->setSuffix("份");
    ui->spinBox_2->setSuffix("份");
    ui->spinBox_3->setSuffix("杯");


}

Widget::~Widget()
{

    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //将客人的点餐信息，存储在文件中
    QString info = ui->comboBox->currentText() + QString::number(ui->spinBox->value()) + "份, " +
                   ui->comboBox_2->currentText() + QString::number(ui->spinBox_2->value()) + "份, " +
                   ui->comboBox_3->currentText() + QString::number(ui->spinBox_3->value())+ "杯" ;
    qDebug() <<info;

    //以追加写的方式打开文件
    std::ofstream file("D:\\Codes\\qt\\QSpinBox_1\\info.txt",std::ios::app);
    if(!file.is_open()){
        qDebug() << "open file failed";
        return;
    }

    //写入点餐信息
    file << info.toStdString() <<std::endl;

    file.close();
}
